package main;
import maths.Vector3d;

public class VerletIntegrator extends LJPotential {
	public void integrate(Particles p,int v1,int v2, double dt){
		 double u =  potential(p,v1,v2);
		 double m = p.getMass(v1);
		 Vector3d force = ljForce(p,v1,v2,u);
		 Vector3d a = force;		 a.multiply(1/m);
		 Vector3d velocity = new Vector3d(p.getVelocity(v1));
		 Vector3d position = new Vector3d(p.getPosition(v1));
		 Vector3d newPosition = new Vector3d(0,0,0);
		 Vector3d newVelocity = new Vector3d(0,0,0);
		 
		 // step 1 												 F
		 //			x(t+dt) = x(t) + v(t)dt + 1/2 a(t)dt^2 ; a = _
		 //														 m
		 velocity.multiply(dt);
		 newPosition.add(newVelocity);
		 a.multiply(0.5*dt*dt);
		 newPosition.add(a);
		 
		 //set a for next step, reset velocity
		 a.multiply(2/(dt*dt));
		 velocity.multiply(1/dt);
		 
		 // step 2						a(t)dt			F(t)dt
		 //			v(t+1/2dt) = v(t) + ______ = v(t) + _______
		 //								  2				  2m
		 newVelocity.add(velocity);
		 newVelocity.add(a);
		 
		 //step 3
		 //			re calculate a(t+dt)
		 //
		 u =  potential(p,v1,v2);
		 force = ljForce(p,v1,v2,u);
		 a = force; 
		 a.multiply(1/m);
		 
		 // step 4						  a(t+dt)dt
		 //			V(t+dt) = v(t+dt/2) + _________
		 //									  2
		 a.multiply(0.5*dt);
		 newVelocity.add(a);
		 
	
}
	
}
